package com.richrail.console.commands;

import com.richrail.model.PrefixedNameGenerator;
import com.richrail.model.TrainFactory;
import com.richrail.model.entities.DepotStorage;
import com.richrail.model.entities.Train;

public class NewTrainCommand
{
	private TrainFactory factory;
	
	private DepotStorage depotStorage;
	
	public NewTrainCommand()
	{
		factory = new TrainFactory(new PrefixedNameGenerator("tr"));
	}
	
	public void setDepotStorage(DepotStorage depotStorage)
	{
		this.depotStorage = depotStorage;
	}
	
	public String execute(String name)
	{
		Train train = factory.create(name);
		return depotStorage.addTrain(train)
			? "train " + train + " created"
			: "train " + train + " already exists";
	}
}
